<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>报价单详情</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" type="text/css" href="../../common/bootstrap/css/bootstrap.css" media="all">
	<link rel="stylesheet" type="text/css" href="../../common/layui/css/layui.css" media="all">
	<link rel="stylesheet" type="text/css" href="../../common/global.css" media="all">
	<link rel="stylesheet" type="text/css" href="../../css/customer_list.css" media="all">
</head>
<style>
	.layui-table-cell {
		white-space: normal !important; /* 允许多行显示 */
		word-break: break-all;          /* 长单词或 URL 地址换行 */
	}

	tbody tr .layui-table-cell {
		height: auto !important;
	}

	.layui-form-item .layui-input-inline {
		font-size: 14px;
		width: 240px;
		margin-right: 10px;
	}

	.main_content_wrap{
		margin-top: 0px;
	}
	.detail_wrap{
		padding: 0 50px;
	}
	.max_w{
		max-width: 950px;
	}
	.must{
		color: red;
	}
	.name_no_border{
		border: none;
		width: 80%;
		font-size: 14px;
	}
	.no-border{
		height: 25px;
		line-height: 25px;
		border: none;
		width: 120px;
	}
	.selectArea{
		max-width: 190px;
	}

	.layui-form-label {
		padding-left: 0;
		width: 95px;
	}
	.layui-form-item .baifenhao{
		width: 130px;
	}
	.layui-form-label{
		padding-left: 0;
		width: 95px;
	}
	.custom-checkbox-label {
		display: flex;
		align-items: center; /* 垂直居中 */
	}

	.layui-form-checkbox span {
		padding: 0 10px;
		height: 100%;
		font-size: 12px;
	}
	.layui-form-checkbox i {
		width: 30px;
		height: 30px;
	}
	.peijian_totall{
		color: #a4a3a3;font-size: 13px;font-weight: bold
	}
	.font_color{
		color: #a4a2a2;
	}
	.qulity{
		width: 80px;
		display: inline-block;
		text-align: left;
	}
</style>
<body>
<!--  -->
<div class="layui-fluid content_box">
	<div class="main_content_wrap">
		<form class="layui-form add_form" lay-filter="addForm" id="addForm" action="">
			<p class="add_title">基础信息</p>
			<input hidden name="id" />
			<div class="layui-form-item">
				<label class="layui-form-label"><span class="must">*</span>询价来源</label>
				<div class="layui-input-inline">
					<select name="bus_from_company_id" lay-verify="required" id="companyList" lay-search disabled>
					</select>
				</div>
				<label class="layui-form-label"><span class="must">*</span>询价单号</label>
				<div class="layui-input-inline">
					<input type="text" name="bus_inquiry_no" class="layui-input" disabled>
				</div>
				<label class="layui-form-label">询价人</label>
				<div class="layui-input-inline">
					<input type="text" name="bus_user_name" class="layui-input">
				</div>
				<label class="layui-form-label">询价人电话</label>
				<div class="layui-input-inline">
					<input type="text" name="bus_user_phone" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">车牌号码</label>
				<div class="layui-input-inline">
					<input type="text" name="vehicle_license_num"  class="layui-input" disabled>
				</div>
				<label class="layui-form-label"><span class="must">*</span>车架号</label>
				<div class="layui-input-inline">
					<input type="text" name="vehicle_frame_no" required  lay-verify="required"  autocomplete="off" class="layui-input" disabled>
				</div>
				<label class="layui-form-label"><span class="must">*</span>车辆品牌</label>
				<div class="layui-input-inline">
					<input type="text" name="brand_name" required  lay-verify="required"  autocomplete="off" class="layui-input" disabled>
				</div>
				<label class="layui-form-label"><span class="must">*</span>车型名称</label>
				<div class="layui-input-inline">
					<input type="text" name="car_model"  required  lay-verify="required" class="layui-input" disabled>
				</div>


			</div>
			<div class="layui-form-item">

				<label class="layui-form-label">报案号</label>
				<div class="layui-input-inline">
					<input type="text" name="service_no"  autocomplete="off" class="layui-input" disabled>
				</div>
				<label class="layui-form-label"><span class="must">*</span>截止时间</label>
				<div class="layui-input-inline">
					<input type="text" name="deadline_datetime" id="deadline_datetime" placeholder="yyyy-MM-DD HH" lay-verify="required" autocomplete="off" class="layui-input" disabled>
				</div>
				<label class="layui-form-label">询价日期</label>
				<div class="layui-input-inline">
					<input type="text" name="add_datetime"  autocomplete="off" class="layui-input" disabled>
				</div>
				<label class="layui-form-label">业务员</label>
				<div class="layui-input-inline">
					<input type="text" name="add_user_name"  autocomplete="off" class="layui-input" disabled>
				</div>


			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span class="must">*</span>配件商</label>
				<div class="layui-input-inline">
					<select name="bus_to_company_id" id="suppliersCompanyList"  lay-filter="bus_to_company_id" lay-search lay-verify="required">
					</select>
				</div>
				<label class="layui-form-label"><span class="must">*</span>原厂件利润率</label>
				<div class="layui-input-inline baifenhao">
					<input name="org_profit_rate" type="number" class="layui-input" id="org_profit_rate"
						   max="100" />
				</div>
				<div class="layui-form-mid layui-word-aux">%</div>
				<label class="layui-form-label"><span class="must">*</span>配套件利润率</label>
				<div class="layui-input-inline baifenhao">
					<input name="matching_profit_rate" type="number" class="layui-input" id="matching_profit_rate"
						   max="100" />
				</div>
				<div class="layui-form-mid layui-word-aux">%</div>
				<label class="layui-form-label"><span class="must">*</span>品牌件利润率</label>
				<div class="layui-input-inline baifenhao">
					<input name="complete_profit_rate" type="number" class="layui-input" id="complete_profit_rate"
						   max="100" />
				</div>
				<div class="layui-form-mid layui-word-aux">%</div>

				<label class="layui-form-label"><span class="must">*</span>适用件利润率</label>
				<div class="layui-input-inline baifenhao">
					<input name="suitable_profit_rate" type="number" class="layui-input" id="suitable_profit_rate"
						   max="100" />
				</div>
				<div class="layui-form-mid layui-word-aux">%</div>
			</div>
			<p class="add_title">零件清单</p>
			<div class="detail_wrap">
				<div class="layui-form-item">
				</div>
				<table class="layui-table max_w" id="infoTable" lay-filter="infoTable"></table>
			</div>
			<!-- 按钮 -->
			<div class="layui-form-item text-center">
				<div class="layui-input-block" style="max-width: none; margin-left: 0">
					<button class="layui-btn site-demo-active" id="createQutation" style="margin-right: 10%;background-color: #00A65A">生成报价单文件</button>
					<button class="layui-btn site-demo-active" id="createQutationNext">下一步</button>
					<button class="layui-btn site-demo-active" id="editQutation" style="display: none">确认中标</button>
					<button class="layui-btn site-demo-active" id="createFile" style="display: none">生成采购和供货单</button>
				</div>
			</div>
		</form>
	</div>
</div>
<script type="text/html" id="eqname">
	{{# if(d.id > 0){ }}
		<div>
			{{d.eq_name}}
			<a class="layui-btn-a" style="background:none;margin-left: 3px" lay-event="copyName" data-eq_name="{{d.eq_name}}">
				<img src="../../img/copy.png" style="width: 25px;"/>
			</a>
		</div>
		<div>
			OE码:<span>{{d.oe_no}}</span>
			{{# if(d.oe_no){ }}
			<a class="layui-btn-a" style="background:none;margin-left:3px" lay-event="copyOe" data-oe-no="{{d.oe_no}}">
				<img src="../../img/copy.png" style="width: 25px;"/>
			</a>
			{{# } }}
		</div>
	{{# }else if(d.id == -2){ }}
		<span class="peijian_totall">{{d.eq_name}}</span>
	{{# }else{ }}
		{{d.eq_name}}
	{{# } }}
</script>
<!--报价-->
<script type="text/html" id="qulityChoose">
	{{# if(d.id != -1){ }}
		{{# if(d.qulity_service_state){ }}
		<div>
			<span class="qulity">服务站:</span><input type="text" class="layui-input no-border price" name="qulity_service_price" value="{{d.qulity_service_price}}" data-type="supplier" data-id="{{d.id}}">
		</div>
		{{# } }}
		{{# if(d.qulity_org_state){ }}
		<div>
			<span class="qulity">原厂原包:</span><input type="text" class="layui-input no-border price" name="qulity_org_price" value="{{d.qulity_org_price}}" data-type="supplier" data-id="{{d.id}}">
		</div>
		{{# } }}
		{{# if(d.qulity_matching_state){ }}
		<div>
			<span class="qulity">配套件:</span><input type="text" class="layui-input no-border price" name="qulity_matching_price" value="{{d.qulity_matching_price}}" data-type="supplier" data-id="{{d.id}}">
			<span class="font_color">{{d.qulity_matching_common?d.qulity_matching_common:''}}</span>
		</div>
		{{# } }}
		{{# if(d.qulity_complete_state){ }}
		<div>
			<span class="qulity">品牌件:</span><input type="text" class="layui-input no-border price" name="qulity_complete_price" value="{{d.qulity_complete_price}}" data-type="supplier" data-id="{{d.id}}">
			<span class="font_color">{{d.qulity_complete_common?d.qulity_complete_common:''}}</span>
		</div>
		{{# } }}
		{{# if(d.qulity_suitable_state){ }}
		<div>
			<span class="qulity">适用件:</span><input type="text" class="layui-input no-border price" name="qulity_suitable_price" value="{{d.qulity_suitable_price}}" data-type="supplier" data-id="{{d.id}}">
			<span class="font_color">{{d.qulity_suitable_common?d.qulity_suitable_common:''}}</span>
		</div>
		{{# } }}
	{{# }else{ }}
	<div><span class="qulity">服务站:</span>{{d.qulity_service_price}}</div>
	<div><span class="qulity">原厂原包件:</span>{{d.qulity_org_price}}</div>
	<div><span class="qulity">配套件:</span>{{d.qulity_matching_price}}</div>
	<div><span class="qulity">品牌件:</span>{{d.qulity_complete_price}}</div>
	<div><span class="qulity">适用件:</span>{{d.qulity_suitable_price}}</div>
	{{# } }}
</script>
<script type="text/html" id="qulityLastChoose">
	{{# if(d.id != -1){ }}
		{{# if(d.qulity_service_state){ }}
		<div>
			<input type="checkbox" name="service" lay-filter="qulity_state" lay-skin="primary" {{d.quote_quilty.includes('service')?'checked':''}} data-id="{{d.id}}">
			<span class="qulity">服务站:</span>{{d.total_service_price}}
		</div>
		{{# } }}
		{{# if(d.qulity_org_state){ }}
		<div class="org-container qulity-container {{(parseFloat(d.total_service_price) > 0 && parseFloat(d.total_org_price) > parseFloat(d.total_service_price))?'must':''}}">
			<input type="checkbox" name="org" lay-filter="qulity_state" lay-skin="primary" {{d.quote_quilty.includes('org')?'checked':''}} data-id="{{d.id}}">
			<span class="qulity">原厂原包件:</span><input type="text" class="layui-input no-border price" name="qulity_org_price" value="{{d.total_org_price}}" data-type="total" data-id="{{d.detail.id}}">
		</div>
		{{# } }}
		{{# if(d.qulity_matching_state){ }}
		<div class="matching-container qulity-container {{(parseFloat(d.total_service_price) > 0 && parseFloat(d.total_matching_price) > parseFloat(d.total_service_price))?'must':''}}">
			<input type="checkbox" name="matching" lay-filter="qulity_state" lay-skin="primary" {{d.quote_quilty.includes('matching')?'checked':''}} data-id="{{d.id}}">
			<span class="qulity">配套件:</span><input type="text" class="layui-input no-border price" name="qulity_matching_price" value="{{d.total_matching_price}}" data-type="total" data-id="{{d.detail.id}}">
		</div>
		{{# } }}
		{{# if(d.qulity_complete_state){ }}
		<div class="complete-container qulity-container {{(parseFloat(d.total_service_price) > 0 && parseFloat(d.total_complete_price) > parseFloat(d.total_service_price))?'must':''}}">
			<input type="checkbox" name="complete" lay-filter="qulity_state" lay-skin="primary" {{d.quote_quilty.includes('complete')?'checked':''}} data-id="{{d.id}}">
			<span class="qulity">品牌件:</span><input type="text" class="layui-input no-border price" name="qulity_complete_price" value="{{d.total_complete_price}}" data-type="total" data-id="{{d.detail.id}}">
		</div>
		{{# } }}
		{{# if(d.qulity_suitable_state){ }}
		<div class="suitable-container qulity-container {{(parseFloat(d.total_service_price) > 0 && parseFloat(d.total_suitable_price) > parseFloat(d.total_service_price))?'must':''}}">
			<input type="checkbox" name="suitable" lay-filter="qulity_state" {{d.quote_quilty.includes('suitable')?'checked':''}} lay-skin="primary" data-id="{{d.id}}">
			<span class="qulity">适用件:</span><input type="text" class="layui-input no-border price" name="qulity_suitable_price" value="{{d.total_suitable_price}}" data-type="total" data-id="{{d.detail.id}}">
		</div>
		{{# } }}
	{{# }else{ }}
	<div><span class="qulity">服务站:</span>{{d.total_service_price}}</div>
	<div><span class="qulity">原厂原包件:</span>{{d.total_org_price}}</div>
	<div><span class="qulity">配套件:</span>{{d.total_matching_price}}</div>
	<div><span class="qulity">品牌件:</span>{{d.total_complete_price}}</div>
	<div><span class="qulity">适用件:</span>{{d.total_suitable_price}}</div>
	{{# } }}
</script>
<!--确认中标-->
<script type="text/html" id="qulity">
	{{# if(d.id > 0){ }}
		{{# if(d.qulity_service_state){ }}
		<div>
			<input type="radio" name="eq_{{d.id}}" {{(d.make_sure_quilty=='qulity_service_price' || (!d.make_sure_quilty && d.detail.quote_quilty.length == 1 && d.detail.quote_quilty[0] =='service') )?'checked':''}} lay-filter="choseQuiltyType" data-qulitytype="qulity_service_price" data-info_type="gys" lay-skin="primary">
			<span class="qulity">服务站:</span><input type="text" class="layui-input no-border price" name="qulity_service_price" value="{{d.qulity_service_price}}" data-type="supplier" data-id="{{d.id}}" data-detail-id="{{d.detail.id}}">
		</div>
		{{# } }}
		{{# if(d.qulity_org_state){ }}
		<div>
			<input type="radio" name="eq_{{d.id}}" {{(d.make_sure_quilty=='qulity_org_price' || (!d.make_sure_quilty && d.detail.quote_quilty.length == 1 && d.detail.quote_quilty[0] =='org' ) )?'checked':''}} lay-filter="choseQuiltyType" data-qulitytype="qulity_org_price" data-info_type="gys"  lay-skin="primary">
			<span class="qulity">原厂原包件:</span><input type="text" class="layui-input no-border price" name="qulity_org_price" value="{{d.qulity_org_price}}" data-type="supplier" data-id="{{d.id}}">
		</div>
		{{# } }}
		{{# if(d.qulity_matching_state){ }}
		<div>
			<input type="radio" name="eq_{{d.id}}" {{(d.make_sure_quilty=='qulity_matching_price' || (!d.make_sure_quilty && d.detail.quote_quilty.length == 1 && d.detail.quote_quilty[0]=='matching' ) )?'checked':''}} lay-filter="choseQuiltyType" data-qulitytype="qulity_matching_price" data-info_type="gys" lay-skin="primary">
			<span class="qulity">配套件:</span><input type="text" class="layui-input no-border price" name="qulity_matching_price" value="{{d.qulity_matching_price}}" data-type="supplier" data-id="{{d.id}}">
			<span class="font_color">{{d.qulity_matching_common?d.qulity_matching_common:''}}</span>
		</div>
		{{# } }}
		{{# if(d.qulity_complete_state){ }}
		<div>
			<input type="radio" name="eq_{{d.id}}" {{(d.make_sure_quilty=='qulity_complete_price' || (!d.make_sure_quilty && d.detail.quote_quilty.length == 1 && d.detail.quote_quilty[0] =='complete' ) )?'checked':''}} lay-filter="choseQuiltyType" data-qulitytype="qulity_complete_price" data-info_type="gys" lay-skin="primary">
			<span class="qulity">品牌件:</span><input type="text" class="layui-input no-border" name="qulity_complete_price" value="{{d.qulity_complete_price}}" data-type="supplier" data-id="{{d.id}}">
			<span class="font_color">{{d.qulity_complete_common?d.qulity_complete_common:''}}</span>
		</div>
		{{# } }}
		{{# if(d.qulity_suitable_state){ }}
		<div>
			<input type="radio" name="eq_{{d.id}}" {{(d.make_sure_quilty=='qulity_suitable_price' || (!d.make_sure_quilty && d.detail.quote_quilty.length == 1 && d.detail.quote_quilty[0]=='suitable' ) )?'checked':''}} lay-filter="choseQuiltyType" data-qulitytype="qulity_suitable_price" data-info_type="gys" lay-skin="primary">
			<span class="qulity">适用件:</span><input type="text" class="layui-input no-border price" name="qulity_suitable_price" value="{{d.qulity_suitable_price}}" data-type="supplier" data-id="{{d.id}}">
			<span class="font_color">{{d.qulity_suitable_common?d.qulity_suitable_common:''}}</span>
		</div>
		{{# } }}
	{{# }else if(d.id == -1){ }}
		<div><span class="qulity">服务站:</span>{{d.qulity_service_price}}</div>
		<div><span class="qulity">原厂原包件:</span>{{d.qulity_org_price}}</div>
		<div><span class="qulity">配套件:</span>{{d.qulity_matching_price}}</div>
		<div><span class="qulity">品牌件:</span>{{d.qulity_complete_price}}</div>
		<div><span class="qulity">适用件:</span>{{d.qulity_suitable_price}}</div>
	{{# }else{ }}
		<span class="peijian_totall">采购总金额：{{d.supplier_sum}}</span>
	{{# } }}
</script>
<!--确认中标-->
<script type="text/html" id="qulityLast">
	{{# if(d.id > 0){ }}
		{{# if(d.qulity_service_state){ }}
		<div>
			<input type="radio" name="quota_{{d.detail.id}}" {{(d.detail.sale_use_quilty=='qulity_service_price' || (!d.detail.sale_use_quilty && d.detail.quote_quilty.length == 1 && d.detail.quote_quilty[0] =='service') )?'checked':''}} lay-filter="choseQuiltyType" data-qulitytype="qulity_service_price" data-info_type="pt" data-id="{{d.detail.id}}" lay-skin="primary">
			<span class="qulity">服务站:</span>{{d.detail.qulity_service_price>0?d.detail.qulity_service_price:d.total_service_price}}
		</div>
		{{# } }}
		{{# if(d.qulity_org_state){ }}
		<div class="org-container qulity-container {{(parseFloat(d.total_service_price) > 0 && parseFloat(d.total_org_price) > parseFloat(d.total_service_price))?'must':''}}">
			<input type="radio" name="quota_{{d.detail.id}}" {{(d.detail.sale_use_quilty=='qulity_org_price' || (!d.detail.sale_use_quilty && d.detail.quote_quilty.length == 1 && d.detail.quote_quilty[0] =='org' ) )?'checked':''}} lay-filter="choseQuiltyType" data-qulitytype="qulity_org_price" data-info_type="pt" data-id="{{d.detail.id}}" lay-skin="primary">
			<span class="qulity">原厂原包件:</span><input type="text" class="layui-input no-border price" name="qulity_org_price" value="{{d.total_org_price}}" data-type="total" data-id="{{d.detail.id}}">
		</div>
		{{# } }}
		{{# if(d.qulity_matching_state){ }}
		<div class="matching-container qulity-container {{(parseFloat(d.total_service_price) > 0 && parseFloat(d.total_matching_price) > parseFloat(d.total_service_price))?'must':''}}">
			<input type="radio" name="quota_{{d.detail.id}}" {{(d.detail.sale_use_quilty=='qulity_matching_price' || (!d.detail.sale_use_quilty && d.detail.quote_quilty.length == 1 && d.detail.quote_quilty[0]=='matching' ) ) ? 'checked':''}} lay-filter="choseQuiltyType" data-qulitytype="qulity_matching_price" data-info_type="pt" data-id="{{d.detail.id}}" lay-skin="primary">
			<span class="qulity">配套件:</span><input type="text" class="layui-input no-border price" name="qulity_matching_price" value="{{d.total_matching_price}}" data-type="total" data-id="{{d.detail.id}}">
		</div>
		{{# } }}
		{{# if(d.qulity_complete_state){ }}
		<div class="complete-container qulity-container {{(parseFloat(d.total_service_price) > 0 && parseFloat(d.total_complete_price) > parseFloat(d.total_service_price))?'must':''}}">
			<input type="radio" name="quota_{{d.detail.id}}" {{(d.detail.sale_use_quilty=='qulity_complete_price' || (!d.detail.sale_use_quilty && d.detail.quote_quilty.length == 1 && d.detail.quote_quilty[0] =='complete' ))?'checked':''}} lay-filter="choseQuiltyType" data-qulitytype="qulity_complete_price" data-info_type="pt" data-id="{{d.detail.id}}" lay-skin="primary">
			<span class="qulity">品牌件:</span><input type="text" class="layui-input no-border price" name="qulity_complete_price" value="{{d.total_complete_price}}" data-type="total" data-id="{{d.detail.id}}">
		</div>
		{{# } }}
		{{# if(d.qulity_suitable_state){ }}
		<div class="suitable-container qulity-container {{(parseFloat(d.total_service_price) > 0 && parseFloat(d.total_suitable_price) > parseFloat(d.total_service_price))?'must':''}}">
			<input type="radio" name="quota_{{d.detail.id}}" {{(d.detail.sale_use_quilty=='qulity_suitable_price' || (!d.detail.sale_use_quilty && d.detail.quote_quilty.length == 1 && d.detail.quote_quilty[0]=='suitable' )) ? 'checked' : ''}} lay-filter="choseQuiltyType" data-qulitytype="qulity_suitable_price" data-info_type="pt" data-id="{{d.detail.id}}" lay-skin="primary">
			<span class="qulity">适用件:</span><input type="text" class="layui-input no-border price" name="qulity_suitable_price" value="{{d.total_suitable_price}}" data-type="total" data-id="{{d.detail.id}}">
		</div>
		{{# } }}
	{{# }else if(d.id == -1){ }}
		<div><span class="qulity">服务站:</span>{{d.total_service_price}}</div>
		<div><span class="qulity">原厂原包件:</span>{{d.total_org_price}}</div>
		<div><span class="qulity">配套件:</span>{{d.total_matching_price}}</div>
		<div><span class="qulity">品牌件:</span>{{d.total_complete_price}}</div>
		<div><span class="qulity">适用件:</span>{{d.total_suitable_price}}</div>
	{{# }else{ }}
		<span class="peijian_totall">销售总金额：{{d.sure_sum}}</span>
	{{# } }}
</script>
<!-- 确认中标表单弹窗 -->
<script type="text/html" id="companyForm">
	<form lay-filter="companyForm" class="layui-form model-form">
		<input name="id" type="hidden"/>
		<div class="layui-form-item">
			<label class="layui-form-label"><span class="must">*</span>经营主体</label>
			<div class="layui-input-inline">
				<select name="business_entity" lay-search lay-verify="required" required>
					<option value="">请选择</option>
					<option value="ht">鸿天</option>
					<option value="cy">车友</option>
					<option value="personal">个体户</option>
				</select>
			</div>

			<label class="layui-form-label"><span class="must">*</span>询价来源</label>
			<div class="layui-input-inline">
				<select name="bus_from_company_id" lay-verify="required" id="upcompanyList" lay-search>
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"><span class="must">*</span>修理厂名称</label>
			<div class="layui-input-inline">
				<input type="text" name="repair_company_name" id="repair_company_name" placeholder="请输入修理厂名称" autocomplete="off" class="layui-input" lay-verify="required">
			</div>

			<label class="layui-form-label"><span class="must">*</span>修理厂电话</label>
			<div class="layui-input-inline">
				<input type="text" name="repair_company_phone" id="repair_company_phone" placeholder="请输入修理厂电话" autocomplete="off" class="layui-input" lay-verify="required|phone">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"><span class="must">*</span>所在地区</label>
			<div class="layui-input-inline selectArea">
				<select name="province" id="province" lay-filter="province" lay-search lay-verify="required" required>
					<option value="">请选择</option>
				</select>
			</div>
			<div class="layui-input-inline selectArea">
				<select name="city" id="city" lay-filter="city" lay-search lay-verify="required" required>
					<option value="">请选择</option>
				</select>
			</div>
			<div class="layui-input-inline selectArea">
				<select name="district" id="district" lay-search>
					<option value="">请选择</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">详细地址</label>
			<div class="layui-input-inline" style="min-width: 590px;">
				<input type="text" name="repair_company_address" placeholder="请输入修理厂地址" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"><span class="must">*</span>询价人</label>
			<div class="layui-input-inline">
				<input type="text" name="bus_user_name" id="bus_user_name" placeholder="请输入询价人姓名" autocomplete="off" class="layui-input" lay-verify="required">
			</div>

			<label class="layui-form-label"><span class="must">*</span>询价人电话</label>
			<div class="layui-input-inline">
				<input type="text" name="bus_user_phone" id="bus_user_phone" placeholder="请输入询价人电话" autocomplete="off" class="layui-input" lay-verify="required|phone">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"><span class="must">*</span>询价人商务费</label>
			<div class="layui-input-inline">
				<input name="loss_assessor_money" type="number" class="layui-input" autocomplete="off" lay-verify="required" required />
			</div>
			<label class="layui-form-label"><span class="must">*</span>修理厂商务费</label>
			<div class="layui-input-inline">
				<input name="repair_company_money" type="number" class="layui-input" autocomplete="off" lay-verify="required" required />
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"><span class="must">*</span>物流</label>
			<div class="layui-input-inline">
				<input type="text" name="logistics_name" placeholder="请输入物流" autocomplete="off" class="layui-input" lay-verify="required" required>
			</div>

			<label class="layui-form-label">备注</label>
			<div class="layui-input-inline">
				<input type="text" name="common" placeholder="" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<div style="display: flex; align-items: center;">
				<div class="custom-checkbox-label" style="display: flex; align-items: center; margin-right: 10px;">
					<input style="width: auto;" type="checkbox" name="choose_freight" lay-filter="choose_freight" title="运费+木架" checked>
					<div class="layui-input-inline" style="width: 220px;">
						<input type="text" name="freight" placeholder="运费+木架" autocomplete="off" class="layui-input freight price" lay-verify="required|num">
					</div>
				</div>

				<div class="custom-checkbox-label" style="display: flex; align-items: center;">
					<input style="width: auto;" type="checkbox" name="choose_tax_rate" lay-filter="choose_tax_rate" title="税点" checked>
					<div class="layui-input-inline">
						<input type="text" name="tax_rate" placeholder="请输入税点" autocomplete="off" class="layui-input tax_rate price" lay-verify="required|num">
					</div>
					<div class="layui-form-mid layui-word-aux">%</div>
				</div>
			</div>
		</div>
		<div class="layui-form-item text-center" style="margin-top: 20px;">
			<button class="layui-btn" type="button"  style="margin-right:2%;" ew-event="closeDialog">取消</button>
			<button class="layui-btn" lay-filter="companyFormSubmit" lay-submit>确认</button>
		</div>
	</form>
</script>
<!--生成报价单弹窗-->
<script type="text/html" id="createQuotationForm">
	<form lay-filter="createQuotationForm" class="layui-form model-form">
		<input name="id" type="hidden"/>
		<div class="layui-form-item">
			<label class="layui-form-label"><span class="must">*</span>文件模版</label>
			<div class="layui-input-inline">
				<select name="business_entity" id="file_template" lay-search lay-verify="required" required>
					<option value="">请选择</option>
					<option value="ht">鸿天</option>
					<option value="cy">车友</option>
					<option value="personal">个体户</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"><span class="must">*</span>带公章</label>
			<div class="layui-input-inline">
				<input type="radio" name="with_seal" lay-filter="choseType" value="1" title="是" checked>
				<input type="radio" name="with_seal" lay-filter="choseType" value="0" title="否">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"><span class="must">*</span>税率</label>
			<div class="layui-input-inline">
				<input name="tax_rate" type="number" class="layui-input" autocomplete="off" lay-verify="required" required />
			</div>
			<div class="layui-form-mid layui-word-aux">%</div>
		</div>
		<div class="layui-form-item text-center">
			<button class="layui-btn" type="button"  style="margin-right:2%;" ew-event="closeDialog">取消</button>
			<button class="layui-btn" lay-filter="createQuotationFormSubmit" lay-submit>生成</button>
		</div>
	</form>
</script>
<script type="text/html" id="createSalesForm">
	<form lay-filter="createSalesForm" class="layui-form model-form">
		<input name="id" type="hidden"/>
		<div class="layui-form-item">
			<label class="layui-form-label"><span class="must">*</span>文件模版</label>
			<div class="layui-input-inline">
				<select name="file_template" lay-search lay-verify="required" required>
					<option value="">请选择</option>
					<option value="ht">鸿天</option>
					<option value="cy">车友</option>
					<option value="personal">个体户</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"><span class="must">*</span>带公章</label>
			<div class="layui-input-inline">
				<input type="radio" name="with_seal" value="1" title="是" checked>
				<input type="radio" name="with_seal" value="0" title="否">
			</div>
		</div>
		<!--<div class="layui-form-item">
			<label class="layui-form-label">运费</label>
			<div class="layui-input-inline">
				<input type="text" name="freight" autocomplete="off" class="layui-input" lay-verify="required">
			</div>
		</div>-->
		<!--<div class="layui-form-item">
			<label class="layui-form-label">税金</label>
			<div class="layui-input-inline">
				<input name="taxes" type="number" class="layui-input" autocomplete="off" />
			</div>
		</div>-->
		<div class="layui-form-item text-center">
			<button class="layui-btn" type="button"  style="margin-right:2%;" ew-event="closeDialog">取消</button>
			<button class="layui-btn" lay-filter="createSalesFormSubmit" lay-submit>生成</button>
		</div>
	</form>
</script>
<script type="text/javascript" src="../../js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../../js/jquery.cookie.js"></script>
<script type="text/javascript" src="../../common/layui/layui2.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script type="text/javascript" src="../../js/main.js"></script>
<script type="text/javascript" src="../../js/area.js"></script>
<script>
	$(function () {
		layui.use(['jquery', 'form', 'laydate', 'admin', 'table'], function () {
			var $ = layui.jquery;
			var form = layui.form;
			var table = layui.table;
			var laydate = layui.laydate;
			var admin = layui.admin;

			var companyList = {};
			var suppliersCompanyList = {};
			var tableIns
			var id = GetQueryString('id');
			var supplier_id = GetQueryString('supplier_id');
			var org_profit_rate = GetQueryString('org_profit_rate')?GetQueryString('org_profit_rate'):'';
			var matching_profit_rate = GetQueryString('matching_profit_rate')?GetQueryString('matching_profit_rate'):'';
			var complete_profit_rate = GetQueryString('complete_profit_rate')?GetQueryString('complete_profit_rate'):'';
			var suitable_profit_rate = GetQueryString('suitable_profit_rate')?GetQueryString('suitable_profit_rate'):'';
			var table_type = 1;
			laydate.render({
				elem: '#deadline_datetime'
				, trigger: 'click',
				type: 'datetime', // 设置类型为 datetime
				format: 'yyyy-MM-dd HH', // 设置显示格式
			});
			form.render();

			var detail_data = [];
			var detailList = [];
			var scrollPosition = {
				table: 0, // 表格容器的滚动位置
				parent: 0 // 父容器的滚动位置（如果适用）
			};
			var cols = [
				{title: '序号',width: 60, templet: function(d){
						if (d.id > 0) {
							return d.LAY_INDEX; // LAY_INDEX 是 Layui 表格为每行自动生成的索引
						}else {
							return '';
						}
					}},
				{field: 'eq_name', title: '零件名称',width: 250, templet: '#eqname'},
				{field: 'num', title: '数量', width: 100, templet: function(d){
					if (d.id == -2) {
						return "<span class='peijian_totall'>"+d.num+"</span>";
					} else {
						return d.num;
					}
				}},
			];
			var DISABLED = 'layui-btn-disabled';

			send_req('Common/basedata', {}, function (data) {
				companyList = data.company_list;
				setSel();
				getInfo();
				getPriceInfo(false)
			});

			function getInfo() {
				send_req('Quotation/getQutationInfo', {id: id}, function (data) {
					detail_data = data;
					detail_data.bus_to_company_id = supplier_id;
					detail_data.org_profit_rate = org_profit_rate;
					detail_data.matching_profit_rate = matching_profit_rate;
					detail_data.complete_profit_rate = complete_profit_rate;
					detail_data.suitable_profit_rate = suitable_profit_rate;
					detail_data.freight = detail_data.freight>0?detail_data.freight:'';
					detail_data.tax_rate = detail_data.tax_rate>0?detail_data.tax_rate:'';
					suppliersCompanyList = detail_data.suppliers;
					if(detail_data.sale_price_state == 0){
						$('#createQutation').show();
						$('#createQutationNext').hide();
						$('#editQutation').hide();
					}else if(detail_data.sale_price_state == 1){
						$('#createQutation').show();
						$('#createQutationNext').show();
						$('#editQutation').hide();
						$('#createFile').hide();
					}else if(detail_data.sale_price_state == 2){
						$('#editQutation').show();
						$('#createQutationNext').hide();
						$('#createQutation').hide();
						table_type=2;
					}else{
                        $('#createQutation').hide();
                        $('#createQutationNext').hide();
						$('#editQutation').show();
						table_type=2;
					}
					setSuppliers()
					form.val('addForm', detail_data);
					form.render();
				});
			}

			function getPriceInfo(is_reload=true,type=1){
				send_req('Quotation/getSupplierPrice', {
					id: id,
					supplier_id:supplier_id,
					type:type,
					org_profit_rate:org_profit_rate,
					matching_profit_rate:matching_profit_rate,
					complete_profit_rate:complete_profit_rate,
					suitable_profit_rate:suitable_profit_rate,
				}, function (data) {
					detailList = data.detail_info;
					detailList = detailList.concat(data.all_info)
					/**/
					if(is_reload){
						reloadTable()
					}else{
						initTable()
					}
				},true);
			}

			//初始化表格
			function initTable(){
				var new_cols = buildCols(detailList,cols);
				tableIns = table.render({
					elem: '#infoTable',
					data: detailList, // 使用本地数据源
					limit:100,
					page: false, // 如果不需要分页，设置为false
					cols: new_cols, // 动态生成的列定义
					done: function (res, curr, count) {
						var tableContainer = document.querySelector('#infoTable').parentElement;
						tableContainer.scrollTop = scrollPosition.table;
						// 如果有父容器，也恢复父容器的滚动位置
						if (scrollPosition.parent !== undefined) {
							document.documentElement.scrollTop = scrollPosition.parent || document.body.scrollTop;
						}
					}
				});
			}
			// 刷新表格
			function reloadTable() {
				var tableContainer = document.querySelector('#infoTable').parentElement;
				scrollPosition.table = tableContainer.scrollTop; // 保存表格容器的滚动位置
				// 如果有父容器，保存父容器的滚动位置
				scrollPosition.parent = document.documentElement.scrollTop || document.body.scrollTop;
				// 表格重载
				var new_cols = buildCols(detailList,cols);
				tableIns.reload({
					cols: new_cols,
					data: detailList // 将新数据与现有缓存合并
				});
			}

			function setSel(companyListId='') {
				var companyStr = '<option value="">全部企业</option>';
				for (var i = 0; i < companyList.length; i++) {
					companyStr += '<option value="' + companyList[i].id + '">' + companyList[i].company_name + '</option>';
				}
				if(companyListId){
					$(companyListId).html(companyStr);
				}else{
					$('#companyList').html(companyStr);
				}
				form.render();
			}

			function setSuppliers(){
				var suppliersStr = new Array();
				for (var i = 0; i < suppliersCompanyList.length; i++) {
					suppliersStr += '<option value="' + suppliersCompanyList[i].id + '">' + suppliersCompanyList[i].suppliers_company_name + '</option>';
				}
				$('#suppliersCompanyList').html(suppliersStr);
				form.render();
			}
			form.render();

			// 获取表格的列
			function buildCols(data,new_cols) {
				// 假设所有行都有相同的键（即字段名）
				var suppliers = data[0];
				// 构建列定义
				if(table_type === 1){
					var colDef = [{
						field: suppliers.add_company_id,
						title: suppliers.suppliers_company_name,
						templet:'#qulityChoose'
					},
						{
							field: '形成报价',
							title: '形成报价',
							templet:'#qulityLastChoose',
							width: 300
						},
						{
							field: 'common',
							title: '备注',
							width: 220
						}
					]
				}else{
					var colDef = [{
						field: suppliers.add_company_id,
						title: suppliers.suppliers_company_name,
						templet:'#qulity'
					},
						{
							field: '形成报价',
							title: '形成报价',
							templet:'#qulityLast',
							width: 300
						},
						{
							field: 'common',
							title: '备注',
							width: 220
						}
					]
				}

				new_cols = new_cols.concat(colDef)
				return [new_cols]; // 注意返回的是二维数组，因为Layui的cols参数是二维数组
			}

			// 辅助函数:构建显示HTML并应用样式
			form.on('select(bus_to_company_id)', function(data) {
				supplier_id = data.value;
				detail_data.bus_to_company_id = supplier_id;
				form.val('addForm', detail_data);
				form.render();
				getPriceInfo();
			});

			$("#profit_rate").on("input",function(e){
				//获取input输入的值
				profit_rate = e.delegateTarget.value;
				detail_data.profit_rate = profit_rate;
				form.render();
				getPriceInfo();
			});
			$("#org_profit_rate").on("input",function(e){
				//获取input输入的值
				org_profit_rate = e.delegateTarget.value;
				detail_data.org_profit_rate = org_profit_rate;
				form.render();
				getPriceInfo();
			});
			$("#matching_profit_rate").on("input",function(e){
				//获取input输入的值
				matching_profit_rate = e.delegateTarget.value;
				detail_data.matching_profit_rate = matching_profit_rate;
				form.render();
				getPriceInfo();
			});
			$("#complete_profit_rate").on("input",function(e){
				//获取input输入的值
				complete_profit_rate = e.delegateTarget.value;
				detail_data.complete_profit_rate = complete_profit_rate;
				form.render();
				getPriceInfo();
			});
			$("#suitable_profit_rate").on("input",function(e){
				//获取input输入的值
				suitable_profit_rate = e.delegateTarget.value;
				detail_data.suitable_profit_rate = suitable_profit_rate;
				form.render();
				getPriceInfo();
			});

			form.on('checkbox(qulity_state)', function(data){
				var elem = data.elem; // 获得 checkbox 原始 DOM 对象
				var checked = elem.checked; // 获得 checkbox 选中状态
				var tag_name = elem.name; // 获取id
				// var eq_id = elem.getAttribute('data-id'); // 获取修改类型
				var tr = elem.closest('tr'); // 使用 jQuery 的 closest 方法，确保你已引入 jQuery
				// 获取当前行的索引
				var index = Array.prototype.indexOf.call(tr.parentNode.children, tr);
				if(checked){
					detailList[index]['quote_quilty'].push(tag_name)
				}else{
					let indexToRemove = detailList[index]['quote_quilty'].indexOf(tag_name);
					if (indexToRemove > -1) {
						detailList[index]['quote_quilty'].splice(indexToRemove, 1);
					}
				}
				send_req('Inquiry/editQuoteQuilty', {
					id:detailList[index].id,
					bus_inquiry_detail_id:detailList[index].bus_inquiry_detail_id,
					quote_quilty:detailList[index]['quote_quilty'].join(','),
				}, function (res) {
					reloadTable()
				}, false)
				form.render(); // 更新渲染
			});

			// 供货采购品质选择
			form.on('radio(choseQuiltyType)', function(data){
				var elem = data.elem; // 获得 checkbox 原始 DOM 对象
				var info_type = elem.getAttribute('data-info_type'); // 获取修改类型
				var qulitytype = elem.getAttribute('data-qulitytype'); // 获取修改类型
				var tr = elem.closest('tr'); // 使用 jQuery 的 closest 方法，确保你已引入 jQuery
				// 获取当前行的索引
				var index = Array.prototype.indexOf.call(tr.parentNode.children, tr);
				var make_sure_quilty ='';
				var sale_use_quilty ='';
				if(info_type === 'gys'){
					make_sure_quilty = qulitytype;
					detailList[index]['make_sure_quilty'] = qulitytype;
					if(!detailList[index]['detail']['sale_use_quilty']){
						detailList[index]['detail']['sale_use_quilty'] = qulitytype;
						sale_use_quilty = qulitytype;
					}
				}else{
					sale_use_quilty = qulitytype;
					detailList[index]['detail']['sale_use_quilty'] = qulitytype;
					if(!detailList[index]['make_sure_quilty']){
						detailList[index]['make_sure_quilty'] = qulitytype;
						make_sure_quilty = qulitytype;
					}
				}
				send_req('Quotation/editSureQuilty', {
					id:detailList[index].id,
					bus_inquiry_detail_id:detailList[index].bus_inquiry_detail_id,
					make_sure_quilty:make_sure_quilty,
					sale_use_quilty:sale_use_quilty,
				}, function (res) {
					getPriceInfo(true,2)
				}, false)
				form.render(); // 更新渲染
			});

			$(document).on('focus', '.price', function() {
				if ($(this).val() == 0) {
					$(this).val(''); // 如果值是'0'，则将其清空
				}
				form.render();
			}).on('blur', '.price', function() {
				var num = Number($(this).val());
				if (isNaN(num) || num <= 0) {
					$(this).val(0); // 如果值是'0'，则将其清空
				}
				form.render();
			});
			document.getElementById('addForm').addEventListener('change', function(event) {
				// 确保我们只监听 input 元素
				if (event.target.tagName.toLowerCase() === 'input' && event.target.classList.contains('layui-input')) {
					// 获取输入框的新值
					var elem = event.target;
					var newValue = event.target.value;
					var tag_name = event.target.name;

					if(isNaN(parseFloat(newValue)) || parseFloat(newValue) < 0){
						layer.msg('价格有误！', {icon:2});
						reloadTable()
						return false
					}

					var eq_id = elem.getAttribute('data-id'); // 获取id
					var tag_type = elem.getAttribute('data-type'); // 获取修改类型

					var tag_types = ['qulity_org_price','qulity_matching_price','qulity_complete_price','qulity_suitable_price'];

					if(tag_type === 'total' && tag_types.includes(tag_name)){
						var tr = event.target.closest('tr'); // 获取最近的 tr 祖先元素
						var index = tr.getAttribute('data-index'); // 零件行
						var servicePrice = parseFloat(detailList[index]['total_service_price']);

						if(servicePrice > 0 && parseFloat(newValue) > servicePrice ){
							var classInfo = '';
							if(tag_name === 'qulity_org_price'){
								classInfo='org-container';
							}
							if(tag_name === 'qulity_matching_price'){
								classInfo='matching-container';
							}
							if(tag_name === 'qulity_complete_price'){
								classInfo='complete-container';
							}
							if(tag_name === 'qulity_suitable_price'){
								classInfo='suitable-container';
							}
							setCellClass(index, classInfo, 'must');
						}else{
							removeCellClass(index,'qulity-container','must')
						}
					}

					var up_data = {
						id:eq_id,
						tag_type:tag_type,
						price:newValue,
						tag_name:tag_name,
					};
					if(tag_name === 'qulity_service_price'){
						up_data.detail_id = elem.getAttribute('data-detail-id');
					}
					if(tag_type === 'supplier' || tag_type === 'total'){
						send_req('Inquiry/editPrice',up_data , function (res) {
							getPriceInfo();
						}, false)
					}
					form.render(); // 更新渲染
				}
			});

			form.on('checkbox(choose_freight)', function(data){
				var elem = data.elem; // 获得 checkbox 原始 DOM 对象
				var checked = elem.checked; // 获得 checkbox 选中状态
				if(checked){
					$('.freight').attr('lay-verify','required|num');
				}else{
					$('.freight').attr('lay-verify','num');
				}
				form.render(); // 更新渲染
			});

			form.on('checkbox(choose_tax_rate)', function(data){
				var elem = data.elem; // 获得 checkbox 原始 DOM 对象
				var checked = elem.checked; // 获得 checkbox 选中状态
				if(checked){
					$('.tax_rate').attr('lay-verify','required|num');
				}else{
					$('.tax_rate').attr('lay-verify','num');
				}
				form.render(); // 更新渲染
			});

			/**复制 OE码**/
			table.on('tool(infoTable)', function(obj){
				var data = obj.data; // 获取当前行数据
				var event = obj.event; // 获取lay-event属性值

				if(event === 'copyOe'){
					copyToClipboard(data.oe_no);
				}else if(event === 'copyName'){
					copyToClipboard(data.eq_name);
				}
			});

			// 复制文本到剪贴板的函数
			function copyToClipboard(text) {
				navigator.clipboard.writeText(text).then(function() {
					layer.msg('复制成功');
				}, function(err) {
					console.error('未能复制文本: ', err);
					layer.msg('复制失败，请手动复制');
				});
			}
			/**复制 OE码**/
			$('#createQutationNext').click(function () {
				table_type = 2;
				$('#createQutation').hide();
				$('#createQutationNext').hide();
				$('#editQutation').show();
				getPriceInfo(true,2);
				return false;
			});
			// 生成报价文件
			$('#createQutation').click(function () {
				var details = layui.table.cache.infoTable;
				details.splice(-1, 1);
				var detail_info = [];
				for (var i = 0; i < details.length; i++) {
					var value = details[i];
					var servicePrice = parseFloat(value.total_service_price);
					if(servicePrice > 0 && parseFloat(value.total_org_price) > servicePrice ){
						setCellClass(i, 'org-container', 'must');
					}
					if(servicePrice > 0 && parseFloat(value.total_matching_price) > servicePrice ){
						setCellClass(i, 'matching-container', 'must');
					}
					if(servicePrice > 0 && parseFloat(value.total_complete_price) > servicePrice ){
						setCellClass(i, 'complete-container', 'must');
					}
					if(servicePrice > 0 && parseFloat(value.total_suitable_price) > servicePrice ){
						setCellClass(i, 'suitable-container', 'must');
					}

					var up_data = {
						"id":value.id,
						'bus_inquiry_detail_id':value.bus_inquiry_detail_id,
						'quote_quilty':value.quote_quilty.join(','),
						'total_service_price':value.total_service_price,
						'total_org_price':value.total_org_price,
						'total_matching_price':value.total_matching_price,
						'total_complete_price':value.total_complete_price,
						'total_suitable_price':value.total_suitable_price,
					};
					detail_info.push(up_data)
				}
				admin.open({
					type: 1,
					area: '500px',
					offset: '65px',
					title: '生成报价单',
					content: $('#createQuotationForm').html(),
					success: function (layero, index) {
						// console.log(layero)
						$(layero).children('.layui-layer-content').css('overflow', 'visible');
						var form_info = {
							'tax_rate':detail_data.tax_rate?detail_data.tax_rate:detail_data.sys_tax_rate
						};

						form.val('createQuotationForm',form_info);
						form.render();

						// 生成报价单
						form.on('submit(createQuotationFormSubmit)', function (d) {
							d.field.add_company_id = supplier_id;
							d.field.id = id;
							d.field.org_profit_rate = org_profit_rate;
							d.field.matching_profit_rate = matching_profit_rate;
							d.field.complete_profit_rate = complete_profit_rate;
							d.field.suitable_profit_rate = suitable_profit_rate;
							d.field.detail_info = JSON.stringify(detail_info);
							// 增加样式
                            $('.site-demo-active').addClass(DISABLED);
                            // 增加属性
                            $('.site-demo-active').attr('disabled', 'disabled');
							// layer.load(); //上传loading
							send_req('Inquiry/createQuotation', d.field, function (res) {
								$('.site-demo-active').removeClass('layui-btn-disabled');
								$('.site-demo-active').removeAttr('disabled');
								layer.closeAll('page');
								layer.closeAll('loading');
								$('#createQutationNext').show();
								location.href = access_baseurl + 'Inquiry/createQuotationFile.html?id='+id+'&add_company_id='+supplier_id+'&with_seal='+d.field.with_seal+'&file_template='+d.field.business_entity;
							}, false)
							getPriceInfo();
							return false;
						});
					}
				})
				return false;
			});

			$('#editQutation').click(function () {
				admin.open({
					type: 1,
					area: '900px',
					offset: '65px',
					title: '确认中标',
					content: $('#companyForm').html(),
					success: function (layero, index) {
						$(layero).children('.layui-layer-content').css('overflow', 'visible');
						generateFirstLevelarea();
						setSel('#upcompanyList');

						if(detail_data.repair_company_address){
							var repair_company_address_arr = detail_data.repair_company_address.split("-");
							if(repair_company_address_arr[0]){
								detail_data.province = repair_company_address_arr[0];
								getSencondLevelarea(detail_data.province);
								form.val('companyForm',detail_data)
								form.render();
							}
							if(repair_company_address_arr[1]){
								detail_data.city = repair_company_address_arr[1];
								getThreeLevelarea(detail_data.city);
							}else{
								detail_data.city = '';
							}
							if(repair_company_address_arr[2]){
								detail_data.district = repair_company_address_arr[2];
							}else{
								detail_data.district = '';
							}
							if(repair_company_address_arr[3]){
								detail_data.repair_company_address = repair_company_address_arr[3];
							}else{
								detail_data.repair_company_address = '';
							}
						}
						form.val('companyForm',detail_data);
						form.render();

						$(".price").on("input",function(e){
							//获取input输入的值
							if(isNaN(parseFloat(e.delegateTarget.value)) || parseFloat(e.delegateTarget.value)<0) {
								$(this).val('');
							}
							form.render();
						});

						$("#bus_user_name").on("input",function(e){
							//获取input输入的值
							var name = e.delegateTarget.value;
							var phone = $("#bus_user_phone").val();
							if(!phone){
								var param = {
									content_type:'user',
									word_type:'name',
									word:name
								}
								getNamePhone(param,"#bus_user_phone");
							}
							form.render();
						});

						$("#bus_user_phone").on("input",function(e){
							//获取input输入的值
							var phone = e.delegateTarget.value;
							var name = $("#bus_user_name").val();
							if(!name){
								var param = {
									content_type:'user',
									word_type:'phone',
									word:phone
								}
								getNamePhone(param,"#bus_user_name");
							}
							form.render();
						});

						$("#repair_company_name").on("input",function(e){
							//获取input输入的值
							var name = e.delegateTarget.value;
							var phone = $("#repair_company_phone").val();
							if(!phone){
								var param = {
									content_type:'repair',
									word_type:'name',
									word:name
								}
								getNamePhone(param,"#repair_company_phone");
							}
							form.render();
						});

						$("#repair_company_phone").on("input",function(e){
							//获取input输入的值
							var phone = e.delegateTarget.value;
							var name = $("#repair_company_name").val();
							if(!name){
								var param = {
									content_type:'repair',
									word_type:'phone',
									word:phone
								}
								getNamePhone(param,"#repair_company_name");
							}
							form.render();
						});
					}
				})
				return false;
			});
			//监听提交---- 确认中标保存
			form.on('submit(companyFormSubmit)', function (d) {
				/*if(!d.field.bus_user_name && !d.field.bus_user_phone){
					layer.msg('询价人电话和姓名至少填一项', {icon:2, time:1500});
					return false;
				}
				if(!d.field.repair_company_name && !d.field.repair_company_phone){
					layer.msg('修理厂电话和名称至少填一项', {icon: 2, time:1500});
					return false;
				}*/
				var details = layui.table.cache.infoTable;
				var detail_infos = [];
				for (let value of details) {
					if(value.id > 0){
						var up_data = {
							"id":value.id,
							'bus_inquiry_detail_id':value.bus_inquiry_detail_id,
							'num':value.num,
							'quote_quilty':value.quote_quilty,
							'make_sure_quilty':value.make_sure_quilty,
							'qulity_service_price':value.qulity_service_price,
							'qulity_org_price':value.qulity_org_price,
							'qulity_matching_price':value.qulity_matching_price,
							'qulity_complete_price':value.qulity_complete_price,
							'qulity_suitable_price':value.qulity_suitable_price,
							'oe_no':value.oe_no,
							'detail':{
								'id':value.detail.id,
								'quote_quilty':value.detail.quote_quilty,
								'sale_use_quilty':value.detail.sale_use_quilty,
								'qulity_service_price':value.total_service_price,
								'qulity_org_price':value.total_org_price,
								'qulity_matching_price':value.total_matching_price,
								'qulity_complete_price':value.total_complete_price,
								'qulity_suitable_price':value.total_suitable_price,
							}
						};
						detail_infos.push(up_data)
					}
				}
				d.field.repair_company_address = d.field.province+'-'+d.field.city+'-'+d.field.district+'-'+d.field.repair_company_address;
				d.field.id = id;
				d.field.add_company_id = supplier_id;
				d.field.sales_no = detail_data.sales_no;
				d.field.detail_info = JSON.stringify(detail_infos);

				// 增加样式
				$('.site-demo-active').addClass(DISABLED);
				// 增加属性
				$('.site-demo-active').attr('disabled', 'disabled');
				layer.load(); //上传loading
				send_req('Quotation/editQuotation', d.field, function (res) {
					$('.site-demo-active').removeClass('layui-btn-disabled');
					$('.site-demo-active').removeAttr('disabled');
					layer.msg('提交成功', {icon: 1, time:1500}, function () {
						layer.closeAll('page');
						layer.closeAll('loading');
						table_type = 2;
						getPriceInfo();
					})
				}, false)
				return false;
			});

			/***************地址区域初始化**********************/
			function generateFirstLevelarea() {
				var area_first_str = '<option value="">请选择</option>';
				for (var i = 0; i < provinceList.length; i++) {
					area_first_str += '<option value="' + provinceList[i].value + '">' + provinceList[i].value + '</option>';
				}
				$('#province').html(area_first_str);
			}

			form.on('select(province)',function (data) {
				var selectedFirstLevel = data.value;
				// 清空并隐藏第二、三级菜单
				$('#city').empty().attr('disabled', true);
				$('#district').empty().attr('disabled', true);
				// 生成第二级菜单
				getSencondLevelarea(selectedFirstLevel)
				form.render();
			});

			function getSencondLevelarea(selectedFirstLevel){
				var secondLevelOptions = '';
				if (selectedFirstLevel) {
					var firstLevelData = provinceList.find(item => item.value === selectedFirstLevel);
					if (firstLevelData && firstLevelData.children && firstLevelData.children.length > 0) {
						secondLevelOptions = '<option value="">请选择</option>';
						for (var j = 0; j < firstLevelData.children.length; j++) {
							secondLevelOptions += '<option value="' + firstLevelData.children[j].value + '">' + firstLevelData.children[j].value + '</option>';
						}
						$('#city').html(secondLevelOptions).attr('disabled', false);
						form.render();
						// 预备生成第三级菜单的逻辑，这里假设第二级选择后会填充第三级
					}
				}
			}
			form.on('select(city)',function (data) {
				var selectedSecondLevel = data.value;
				getThreeLevelarea(selectedSecondLevel)
				form.render();
			});
			function getThreeLevelarea(selectedSecondLevel){
				var selectedFirst = $('#province').val();
				var firstLevelData = provinceList.find(item => item.value === selectedFirst);
				var secondLevelData = firstLevelData.children.find(item => item.value === selectedSecondLevel);
				if (secondLevelData && secondLevelData.children && secondLevelData.children.length > 0) {
					var thirdLevelOptions = '<option value="">请选择</option>';
					for (var k = 0; k < secondLevelData.children.length; k++) {
						thirdLevelOptions += '<option value="' + secondLevelData.children[k].value + '">' + secondLevelData.children[k].value + '</option>';
					}
					$('#district').html(thirdLevelOptions).attr('disabled', false).parent().show();
				} else {
					$('#district').empty().attr('disabled', true);
				}
				form.render();
			}
			/***************地址区域初始化**********************/

			function setCellClass(rowIndex, fieldName, className) {
				var row = $('#infoTable').next().find('.layui-table-body tbody tr').eq(rowIndex);
				if (row.length) {
					var cell = row.find('.' + fieldName + '');
					cell.addClass(className);
					layer.msg('请核对配件价格',{icon: 2});
				}
			}

			function removeCellClass(rowIndex, fieldName, className) {
				var row = $('#infoTable').next().find('.layui-table-body tbody tr').eq(rowIndex);
				if (row.length) {
					var cell = row.find('.' + fieldName + '');
					cell.removeClass(className);
				}
			}


			function getNamePhone(param,id){
				send_req('Common/getNamePhone', param, function (data) {
					if(data){
						$(id).val(data)
					}
					form.render();
				});
			}

			form.verify({
				num: function(value, item){ // value:表单的值、item:表单的DOM对象
					if (value !== '') {
						var num = Number(value);
						if (isNaN(num) || num< 0) {
							return '格式有误';
						}
					}
				},
				phone:function (value) {
					if(value !== ''){
						if(!/^1\d{10}$|^(0\d{2,3}-|$0\d{2,3}$|0\d{2,3})?\d{7,8}(-\d{3,4})?$/.test(value)){
							return '电话格式有误'
						}
					}
				},
				// phone: [/^1\d{10}$|^(0\d{2,3}-|$0\d{2,3}$|0\d{2,3})?\d{7,8}(-\d{3,4})?$/, '电话格式有误'],
			});
		});
	});
</script>
</body>
</html>